<extend name="Layout/application"/>

<block name="content">
    <div class="row">
        <div class="col-md-12">

            <div class="row">
                <div class="col-md-8">
                    <div class="page-header">
                        <h1>系统首页</h1>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-heading">友情链接</div>


                        <div class="panel-body">

                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="Checkedall"></th>
                                    <th>ID</th>
                                    <th>名称</th>
                                    <th>链接</th>
                                    <th>排序</th>
                                </tr>
                                </thead>
                                <form method="post" action="" id="form">


                                <volist name="links" id="l">
                                <tbody>



                                <tr>
                                    <td><input type="checkbox" class="del_checked" name="delete_id[]" value="{{$l.id}}"></td>
                                    <td class="id">{{$l.id}}</td>
                                    <td class="name"><a href="{{$l.url}}" target="_blank">{{$l.name}}</a></td>
                                    <td class="url">{{$l.url}}</td>
                                    <input type="hidden" name="sort_id[]" value="{{$l.id}}">
                                    <td><input type="text" value="{{$l.sort_order}}" name="sort_order[]" ></td>
                                    <td>
                                        <a class="edit"  href="" data-toggle="modal" data-target="#edit">
                                        <span class="glyphicon glyphicon-pencil"></span>
                                        </a>
                                        <a href="{{:U('del',array(id=>$l['id']))}}">
                                        <span class="glyphicon glyphicon-trash"></span>
                                        </a>
                                    </td>


                                </tr>

                                </tbody>
                                    </volist>
                                </form>


                            </table>
                            <!-- Button trigger modal -->


                            <!-- Modal -->
                            <div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                            <h4 class="modal-title" id="myModalLabel">增加</h4>
                                        </div>
                                        <div class="modal-body">
                                            <form class="form-horizontal" role="form" method="post" action="{{:U('do_add')}}">


                                                <div class="form-group">

                                                    <label for="name" class="col-sm-2 control-label">名称</label>
                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="" placeholder="" name="name" value="">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="url" class="col-sm-2 control-label">链接</label>
                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="" placeholder="" name="url" value="">
                                                    </div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                    <button type="submit" class="btn btn-primary">确定</button>
                                                </div>

                                            </form>
                                        </div>

                                    </div>
                                </div>
                            </div>

                            <!-- Button trigger modal -->


                            <!-- Modal -->
                            <div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                            <h4 class="modal-title" id="">修改</h4>
                                        </div>
                                        <div class="modal-body">
                                            <form class="form-horizontal" role="form" method="post" action="{{:U('do_edit')}}">
                                                <input type="text" name="id" value="" class="id">

                                                <div class="form-group">

                                                    <label for="name" class="col-sm-2 control-label">名称</label>
                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="name" placeholder="" name="name" value="">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label for="url" class="col-sm-2 control-label">链接</label>
                                                    <div class="col-sm-10">
                                                        <input type="text" class="form-control" id="url" placeholder="" name="url" value="">
                                                    </div>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                    <button type="submit" class="btn btn-primary">保存</button>
                                                </div>

                                            </form>

                                        </div>

                                    </div>
                                </div>
                            </div>



                        </div>
                    </div>
                </div>


                <div class="col-md-2">
                    <div class="list-group">
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category" data-toggle="modal" data-target="#add">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true" ></span> 新增 (add)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_order">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 排序 (sort)
                        </a>
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info destroy_checked" >
                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除 (delete)
                        </a>

                    </div>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="js">
    <script>
        $(function () {
            $(".edit").click(function () {
                var id=$(this).parent().siblings(".id").text();
                var name=$(this).parent().siblings(".name").text();
                var url=$(this).parent().siblings(".url").text();
                $("#name").val(name);
                $("#url").val(url);
                $(".id").val(id);


            });

            $("#Checkedall").click(function () {
                $(".del_checked").prop("checked", this.checked);
            });

            $(".destroy_checked").click(function () {
                var length = $(".del_checked:checked").length;
                if (length == 0) {
                    alert('您必须选中一条');
                    return false;
                }

                $("#form").attr('action', "{{:U('destroy_checked')}}").submit();
            });

            $(".sort_order").click(function () {
                 $("#form").attr('action',"{{:U('sort_order')}}").submit();
            })



        })
    </script>

</block>